/*
Illuminator (LED drawing tool for iPhone)
Copyright (C) 2008
Nik S Denin
Ivan A Vlasov
Dmitriy A Jackovlev

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#import "MainView.h"

@implementation MainView

- (id)initWithFrame:(CGRect)frame
{
	frame.origin.x = frame.origin.y = 0.0;

	if ((self = [super initWithFrame:frame]) != nil)
	{
		m_field = [[DrawField alloc] initWithFrame:frame];
		[m_field setDelegate:self];

		m_settingsView = [[SettingsView alloc] initWithFrame:frame];
		[m_settingsView setDelegate:self];
		
		m_twitterView = [[TwitterView alloc] initWithFrame:frame];
		[m_twitterView setDelegate:self];
				
		[self transition:0 toView:m_field];
	}
	return self;
}

- (void)dealloc
{
	[m_field release];
	[m_settingsView release];
	[super dealloc];
}

- (void)showTwitterView
{
	[self transition:1 toView:m_twitterView];
}

- (void)showDrawField
{
	[self transition:2 toView:m_field];
}

/* Usage:
[m_delegate mail:[NSData dataWithContentsOfFile:@"/tmp/i.png"]];
*/

- (id)mail:(NSData *)pngData
{
	TRACE(@"0");
	mailController = [[MailComposeController alloc] initForContentSize:[UIHardware fullScreenApplicationContentRect].size];
	[mailController setDelegate:self];
	[mailController initializeUI];
	TRACE(@"%@ %@",mailController,[mailController sendingEmailAddress]);
	if ([pngData length])
		[mailController addInlineAttachmentWithData:pngData preferredFilename:@"IlluminatorSnap.png" mimeType:@"image/png"];
	[self transition:1 toView:[mailController view]];
}

- (void)mailComposeControllerCompositionFinished:(id)idd
{
	TRACE(@"Mail composition finished...");
	[mailController deliverMessage];
	[self transition:2 toView:m_field];
}

- (void)mailComposeControllerDidAttemptToSend:(id)fp8 mailDelivery:(id)fp12
{
	TRACE(@"Trying to end send mail...");
	[UIApp setStatusBarShowsProgress:NO];
	if ([mailController error])
	{
		//alertSheet with [[mailController error] localizedDescription]
		TRACE(@"SomeError:%@",[[mailController error] localizedDescription]);
	}
}

- (void)mailComposeControllerWillAttemptToSend:(id)fp8
{
	[UIApp setStatusBarShowsProgress:YES];
	TRACE(@"Trying to start send mail... %@",fp8);
}

- (void)mailComposeControllerDidAttemptToSaveDraft:(id)fp8 account:(id)fp12 result:(int)fp16
{
	TRACE(@"Trying to save draft... %@\n%@\n%d",fp8,fp12,fp16);
}


@end // MainView
